package NewCoder;

import java.util.ArrayList;
import java.util.List;

public class BM34 {
    public boolean isValidBST (TreeNode root) {
        // write code here
        if(root==null) return false;
        List<Integer> list =new ArrayList<>();
        pre(list,root);
        int[] arr=new int[list.size()];
        for(int i=0;i<arr.length;i++){
            arr[i]=list.get(i);
        }
        for(int i=0;i<arr.length-1;i++){
            if(arr[i]>arr[i+1]){
                return false;
            }
        }
        return true;
    }
    private void pre(List<Integer> list , TreeNode root){
        if(root==null) return;
        pre(list,root.left);
        list.add(root.val);
        pre(list,root.right);
    }
}
